const excel = require("node-excel-export");
const fs = require("fs");
const styles = {
  headerDark: {
    fill: {
      fgColor: {
        rgb: "FF0000",
      },
    },
    font: {
      color: {
        rgb: "000000",
      },
      sz: 14,
    },
  },
};

const specification = {
  FLIGHT_AIRLINE_ID: {
    displayName: "FLIGHT_AIRLINE_ID", // <- Here you specify the column header
    headerStyle: styles.headerDark, // <- Header style
    width: 120, // <- width in pixels
  },
  StartAirportName: {
    displayName: "StartCity",
    headerStyle: styles.headerDark,
    width: 120, // <- width in chars (when the number is passed as string)
  },
  EndAirportName: {
    displayName: "EndCity",
    headerStyle: styles.headerDark,
    width: 220, // <- width in pixels
  },
  airline_str: {
    displayName: "AirLine",
    headerStyle: styles.headerDark,
    width: 220, // <- width in pixels
  },
  // airline_str2: {
  //   displayName: "AirLine2",
  //   headerStyle: styles.headerDark,
  //   width: 220, // <- width in pixels
  // },
};

const dataset = [
  { customer_name: "IBM", status_id: 1, note: "some note" },
  { customer_name: "HP", status_id: 0, note: "some note" },
  { customer_name: "MS", status_id: 0, note: "some note" },
];

const merges = [{ start: { row: 2, column: 6 }, end: { row: 2, column: 10 } }];

function outExcel(dataset) {
  const report = excel.buildExport([
    {
      name: "T_CityToCity", // <- Specify sheet name (optional)
      merges: merges, // <- Merge cell ranges
      specification: specification,
      data: dataset,
    },
  ]);
  fs.writeFile("./result/out.xlsx", report, "binary", (err) => {
    if (err) {
      console.log(err);
    }
  });
}
module.exports = { outExcel };
